package com.kobe.controller;

import com.kobe.common.annotation.Log;
import com.kobe.common.annotation.RepeatSubmit;
import com.kobe.common.core.controller.BaseController;
import com.kobe.common.core.domain.AjaxResult;
import com.kobe.common.core.domain.R;
import com.kobe.common.core.validate.AddGroup;
import com.kobe.common.core.validate.EditGroup;
import com.kobe.common.enums.BusinessType;
import com.kobe.common.core.page.TableDataInfo;
import com.kobe.common.utils.poi.ExcelUtil;
import com.kobe.domain.dto.SysRemindDTO;
import com.kobe.domain.vo.SysRemindVO;
import com.kobe.service.RemindService;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import javax.servlet.http.HttpServletResponse;
import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
import java.util.Arrays;
import java.util.List;

/**
 * 事件提醒
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/remind/handel")
public class RemindController extends BaseController {

    private final RemindService remindService;

    /**
     * 查询代办事件列表
     */
    @GetMapping("/getRemindList")
    public TableDataInfo<SysRemindVO> getRemindList(SysRemindDTO sysRemindDTO) {
        startPage();
        List<SysRemindVO> remindList = remindService.queryRemindList(sysRemindDTO);
        return getDataTable(remindList);
    }

    /**
     * 查询事件统计
     */
    @GetMapping("/getRemindCount")
    public R getRemindCount(SysRemindDTO bo){
        Long aLong = remindService.queryRemindCount(bo);
        return R.ok(aLong);
    }

    /**
     * 查询事件提醒列表
     */
    @GetMapping("/list")
    public TableDataInfo<SysRemindVO> list(SysRemindDTO bo) {
        startPage();
        return getDataTable(remindService.queryPageList(bo));
    }

    /**
     * 导出事件提醒列表
     */
    @Log(title = "事件提醒", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response) {
        ExcelUtil<SysRemindVO> util = new ExcelUtil<>(SysRemindVO.class);
        util.importTemplateExcel(response, "事件数据");
    }

    /**
     * 获取事件提醒详细信息
     */
    @GetMapping("/{remindId}")
    public R<SysRemindVO> getInfo(@NotNull(message = "主键不能为空")
                                    @PathVariable Long remindId) {
        return R.ok(remindService.queryById(remindId));
    }

    /**
     * 新增事件提醒
     */
    @Log(title = "事件提醒", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public AjaxResult add(@Validated(AddGroup.class) @RequestBody SysRemindDTO bo) {
        return AjaxResult.success(remindService.insertByBo(bo));
    }

    /**
     * 修改事件提醒
     */
    @Log(title = "事件提醒", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public AjaxResult edit(@Validated(EditGroup.class) @RequestBody SysRemindDTO bo) {
        return toAjax(remindService.updateByBo(bo));
    }

    /**
     * 删除事件提醒
     */
    @Log(title = "事件提醒", businessType = BusinessType.DELETE)
    @DeleteMapping("/{remindIds}")
    public AjaxResult remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable Long[] remindIds) {
        return toAjax(remindService.deleteWithValidByIds(Arrays.asList(remindIds), true));
    }

}
